#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>

#define MIN(x, y)	((x) < (y) ? (x) : (y))
#define MAX(x, y)	((x) > (y) ? (x) : (y))
#define DATA_TYPE	long long
#define SANITY_MAX	100UL
#define DEBUG
volatile unsigned long int sanity_chk = 0UL;

typedef struct Node {
	long long sum;
	long long val;
	long long add;
	long long min;
	int l;
	int r;
	bool valid_val;
	struct Node *left;
	struct Node *right;
} Node;


Node *
init(int l, int r)
{
	Node *node;
	node = (Node*) malloc(sizeof(Node));
	node->l         = l;
	node->r         = r;
	node->sum       = 0LL;
	node->val       = 0LL;
	node->add       = 0LL;
	node->min       = 0LL;
	node->valid_val = true;
	if (l != r) {
		node->left  = init(l, (l + r) / 2);
		node->right = init((l + r) / 2 + 1, r);
	} else {
		node->left  = NULL;
		node->right = NULL;
	}
	return (node);
}

#ifdef DEBUG
inline void
print_node(Node *node, const char *caller)
{
	fprintf(stderr, "%s: node = <sum=%lld val=%lld add=%lld min=%lld "
		"l=%d r=%d%s>\n",
		caller, node->sum, node->val, node->add, node->min,
		node->l, node->r, node->valid_val ? " valid_val" : ""
	       );
}
#endif

/*
 * What is this for?
 */
inline void
set_node_val(Node *node, long long val)
{
	node->val       = val;
	node->valid_val = true;
	node->sum       = val * (node->r - node->l + 1);
}

/*
 * Set all elements between 'l' and 'r' value to 'val'
 */
void
set(Node *node, int l, int r, long long val)
{
#ifdef DEBUG
	print_node(node, "set()");
#endif
	if (node->l == l && node->r == r) {
#ifdef DEBUG
		fprintf(stderr, "set(node, l=%d, r=%d, val=%lld):"
			" node полностью накрывает [l;r]"
			" вызываем set_node_val(node, val=%lld)\n",
			l, r, val, val);
#endif
		return (set_node_val(node, val));
	}
	if (node->valid_val) {
#ifdef DEBUG
		fprintf(stderr, "set(node, l=%d, r=%d, val=%lld):"
			" node->valid_val, пропихиваем вниз val - add\n",
			l, r, val);
#endif
		node->valid_val = false;
		set_node_val(node->left,  node->val - node->add);
		set_node_val(node->right, node->val - node->add);
	}
	if (r <= node->left->r)
		set(node->left,  l, MIN(r, node->left->r), val - node->add);
	else if (l >= node->right->l)
		set(node->right, MAX(l, node->right->l), r, val - node->add);
	else {
#ifdef DEBUG
		fprintf(stderr, "set(node, l=%d, r=%d, val=%lld): "
			"странно…\n",
			l, r, val);
#endif
		set(node->left,  l, node->left->r,  val - node->add);
		set(node->right, node->right->l, r, val - node->add);
	}
	node->sum = node->left->sum + node->right->sum +
		node->left->add + node->right->add;
#ifdef DEBUG
	fprintf(stderr, "set(node, l=%d, r=%d, val=%lld):"
		" node->sum = %lld\n",
		l, r, val, node->sum);
#endif
}

long long
sum(Node *node, int l, int r)
{
#ifdef DEBUG
	print_node(node, "sum()");
#endif
	if (l > r) {
#ifdef DEBUG
		fprintf(stderr, "sum(node=%016p, l=%d, r=%d): "
			"l > r, returning 0LL\n",
			node, l, r);
#endif
		return (0LL);
	}
	if (l == node->l && r == node->r) {
#ifdef DEBUG
		fprintf(stderr, "sum(node=%016p, l=%d, r=%d): "
			"полностью покрывает отрезок [l;r]\n",
			node, l, r);
#endif
		return (node->sum + node->add);
	}
	if (node->valid_val) {
#ifdef DEBUG
		fprintf(stderr, "sum(node=%016p, l=%d, r=%d):"
			" node->valid_val,"
			" returning (r=%d - l=%d) *"
			" node->val=%lld + node->add=%lld\n",
			node, l, r, r, l, node->val, node->add);
#endif
		return ((r - l + 1) * node->val + node->add);
	}
	return (sum(node->left, l, MIN(r, node->left->r)) +
		sum(node->right, MAX(l, node->right->l), r) + node->add);
}

/* Вот это прикол! */

void
add(Node *node, int l, int r, long long diff)
{
#ifdef DEBUG
	print_node(node, "add()");
#endif
	if (l == node->l && r == node->r) {
#ifdef DEBUG
		fprintf(stderr,
			" node полностью покрывает отрезок [l,r]. "
			"node->add = %lld\n",
			node->add + diff);
#endif
		node->add += diff;
		return;
	}

	/*
	 * Pass teh request to children nodes
	 */
	if (node->valid_val) {
#ifdef DEBUG
		fprintf(stderr, "add(node=%016p, l=%d, r=%d, diff=%lld):"
			" node=<l=%d r=%d sum=%lld val=%lld add=%lld min=%lld>"
			" Пропихиваем node->valid_val вниз,"
			" node->add = %lld + %lld\n",
			node, l, r, diff,
			node->l, node->r, node->sum, node->val, node->add, node->min,
			node->add, diff);
#endif
		node->valid_val = false;
		set_node_val(node->left,  node->val - node->add);
		set_node_val(node->right, node->val - node->add);
		node->add += diff;
	}
	if (r <= node->left->r) {
#ifdef DEBUG
		fprintf(stderr, "add(node=%016p, l=%d, r=%d, diff=%lld):"
			" node=<l=%d r=%d sum=%lld val=%lld add=%lld min=%lld>:"
			" вызываем add для левого ребёнка\n",
			node, l, r, diff,
			node->l, node->r, node->sum, node->val, node->add, node->min);
#endif
		add(node->left,  l, MIN(r, node->left->r),  diff - node->add);
	}
	if (l >= node->right->l) {
#ifdef DEBUG
		fprintf(stderr, "add(node=%016p, l=%d, r=%d, diff=%lld):"
			" node=<l=%d r=%d sum=%lld val=%lld add=%lld min=%lld>:"
			" вызываем add для правого ребёнка\n",
			node, l, r, diff,
			node->l, node->r, node->sum, node->val, node->add, node->min);
#endif
		add(node->right, MAX(l, node->right->l), r, diff - node->add);
	}
	node->min = MIN(node->left->min + node->left->add,
				node->right->min + node->right->add);
	node->sum = node->left->sum + node->right->sum +
		node->left->add + node->right->add;
#ifdef DEBUG
	fprintf(stderr, "add(node=%016p, l=%d, r=%d, diff=%lld):"
		" node->min=%lld\n", node, l, r, diff, node->min);
#endif
}

long long
min(Node *node, int l, int r)
{
	long long result = LONG_MAX;

#ifdef DEBUG
	sanity_chk++;
	if (sanity_chk >= SANITY_MAX) {
		fprintf(stderr, "min(node=%016p, l=%d, r=%d):"
			" number of operations has gone insane, aborting\n",
			node, l, r);
		return (0LL);
	}
	print_node(node, "min()");
#endif
	if (l == node->l && r == node->r)
		return (node->min + node->add);

	if (l <= node->left->r) {
		result = MIN(min(node->left, l, MIN(r, node->left->r)) + node->add,
			     result);
	}
	if (r >= node->right->l) {
		result = MIN(min(node->right, MAX(l, node->right->l), r) + node->add,
			     result);
	}

	return (result);
}

void
free_tree(Node *node)
{
	if (node->left)  free_tree(node->left);
	if (node->right) free_tree(node->right);
	free(node);
}

int
main(int argc, char **argv)
{
	char line[512];
	char *read_ptr;
	int a;
	int b;
	long long x;
	Node *root = NULL;

	if (argc > 1) root = init(0, atoi(argv[1]));
	else          root = init(0, 100000);

	while ((read_ptr = fgets(line, 512, stdin))) { /* SHUT UP CLANG */
		if (!strncmp(line, "Set", 3UL)) {
			(void) sscanf(read_ptr + 3, "(%d, %d, %lld)",
					&a, &b, &x);
			set(root, a, b, x);
		} else if (!strncmp(line, "Add", 3UL)) {
			(void) sscanf(read_ptr + 3, "(%d, %d, %lld)",
					&a, &b, &x);
			add(root, a, b, x);
		} else if (!strncmp(line, "Min", 3UL)) {
			(void) sscanf(read_ptr + 3, "(%d, %d)", &a, &b);
			(void) printf("%lld\n", min(root, a, b));
			sanity_chk = 0UL;
		} else if (!strncmp(line, "Sum", 3UL)) {
			(void) sscanf(read_ptr + 3, "(%d, %d)", &a, &b);
			(void) printf("%lld\n", sum(root, a, b));
		} else {
			fprintf(stderr, "wtf\n");
		}
	}
	free_tree(root);
	return (0);
}
